﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace ProjectRoughWork
{
    class BaseActor : IActor
    {
        /// <summary>
        /// Default constructor. Currently does nothing for the base class
        /// </summary>

        public BaseActor()
        {
        }

        /// <summary>
        /// 1 Parameter constructor. Initializes the actor's position
        /// </summary>
        /// <param name="initPos">The initial posiiton of the actor</param>

        public BaseActor(Vector3 initPos)
        {
            mPos = initPos;
        }

        public Matrix getMatrix()
        {
            return mMat;
        }

        public void setMatrix(Matrix newMatrix)
        {
            mMat = newMatrix;
        }

        /// <summary>
        /// Returns the current rotation of the actor
        /// </summary>
        /// <returns>The current rotation of the actor</returns>

        public float getRotation()
        {
            return mRotation;
        }

        /// <summary>
        /// Set the rotation of the actor to the new rotation given
        /// </summary>
        /// <param name="newRotation">The new rotation to give the actor</param>

        public virtual void setRotation(float newRotation)
        {

            mRotation = newRotation;

        }

        public float NormalizeRotation(float angle)
        {
            while (angle < -MathHelper.Pi)
            {
                angle += MathHelper.TwoPi;
            }

            while (angle > MathHelper.Pi)
            {
                angle -= MathHelper.TwoPi;
            }

            return angle;
        }

        /// <summary>
        /// Returns the actor's ID
        /// </summary>
        /// <returns>Returns the actor's ID</returns>

        public int getID()
        {
            return mID;
        }

        /// <summary>
        /// Sets the actor's ID to the new ID given
        /// </summary>
        /// <param name="newID">The new ID to be given to the actor</param>

        public void setID(int newID)
        {
            mID = newID;
        }

        public string getType()
        {
            return mType;
        }

        /// <summary>
        /// Returns the actor's velocity
        /// </summary>
        /// <returns>Returns the actor's velocity</returns>

        public Vector3 getVelocity()
        {
            return mVel;
        }

        /// <summary>
        /// Sets the actor's velocity
        /// </summary>
        /// <param name="newVelocity">The new velocity to give the actor</param>

        public virtual void setVelocity(Vector3 newVelocity)
        {
            mVel = newVelocity;

            mVel.X = MathHelper.Clamp(mVel.X, -maxVel, maxVel);
            mVel.Y = MathHelper.Clamp(mVel.Y, -maxVel, maxVel);
            mVel.Z = MathHelper.Clamp(mVel.Z, -maxVel, maxVel);
        }

        

        public Vector3 Position
        {
            get { return mPos; }
            set { mPos = value; }
        }

         
          
        /// <summary>
        /// Returns the position of the actor
        /// </summary>
        /// <returns>The position of the actor</returns>

        public Vector3 getPosition()
        {
            return mPos;
        }

        /// <summary>
        /// Sets the position of the actor to the new position given
        /// </summary>
        /// <param name="newPos"></param>

        public virtual void setPosition(Vector3 newPos)
        {
            mOrigin = newPos + (mOrigin - mPos);
            
            mPos = newPos;

            bSphere.Center = mOrigin;
        }

        public Vector3 getOrigin()
        {
            return mOrigin;
        }

        public void setOrigin(Vector3 newOrigin)
        {
            mOrigin = newOrigin;
        }

        public float OffsetRotation
        {
            get { return mOffsetRotation; }
            set { mOffsetRotation = value; }
        }

        public BoundingSphere BSphere
        {
            get { return bSphere; }
            set { bSphere = value; }
        }

        public float MaxVelocity
        {
            get { return maxVel; }
            set { maxVel = value; }
        }

        public float MaxAcceleration
        {
            get { return maxAccel; }
            set { maxAccel = value; }
        }

        /// <summary>
        /// View Matrix Accessor and Mutator
        /// </summary>

        public Matrix View
        {
            get { return view; }
            set { view = value; }
        }

        /// <summary>
        /// Projection Matrix Accessor and Mutator
        /// </summary>

        public Matrix Projection
        {
            get { return projection; }
            set { projection = value; }
        }

        public bool Moving
        {
            get { return moving; }
            set { moving = value; }
        }

        public bool VIsPhysical()
        {
            return true;
        }

        public bool VIsGeometrical()
        {
            return geometry;
        }

        //Data Members

        public void VRotateY(float angle){}
        public virtual void VOnUpdate(){}
        public virtual void VRender(){}

        protected int mID;
        protected string mType;

        public Matrix mMat;
        protected Matrix view;
        protected Matrix projection;
        protected float mRotation;
        protected float mOffsetRotation;
        protected Vector3 mVel;
        protected float maxVel;
        protected float maxAccel;
        public Vector3 mPos;
        protected Vector3 mOrigin;
        protected float collisionRadius;

        protected BoundingSphere bSphere;
        protected bool geometry;
        protected bool moving;
    }
}
